﻿using System;
using System.Collections.Generic;
using System.Text;
using IRCServer.Entities;
using IRCServer.Backend;
using IRCServer.Utilities;
using IRC.Utilities;

namespace IRCServer.CommandHandlers
{
    abstract class UserRegistrationCommandHandler : CommandHandlerBase
    {
        private string nickname;

        protected bool UpdateConnectionState(ClientSession session)
        {
            if (session.User != null && session.User.Username != null && session.User.Nickname != null)
            {
                session.ConnectionState = ConnectionState.Registered;
                nickname = session.User.Nickname;
                return true;
            }
            return false;
        }

        protected void AddUserToDaemon()
        {
            Logger.Instance.Info("Sending Add User to routing daemon");
            ServerBackend.Instance.RoutingDaemon.SendCommand(
                CommandGenerator.GenerateCommand(CommandType.ADDUSER, nickname));
        }

        protected void RemoveUserFromDaemon()
        {
            Logger.Instance.Info("Sending Remove User to routing daemon");
            ServerBackend.Instance.RoutingDaemon.SendCommand(
                CommandGenerator.GenerateCommand(CommandType.REMOVEUSER, nickname));
        }
    }
}
